const fp = require('lodash/fp');
const { Container, Maybe } =  require('./support');

//练习1
let maybe = Maybe.of([5, 6, 1]);
let ex1 = () => {
  let result = maybe.map(x => fp.map(fp.add(10), x));
  return result._value;
}
console.log('---练习1---', ex1());

//练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']);
let ex2 = () => {
  let result = xs.map(x => fp.first(x));
  return result._value;
}
console.log('---练习2---', ex2());

//练习3
let sefeProp = fp.curry(function(x,o) {
  return Maybe.of(o[x]);
});
let user = { id: 2, name: 'Albert' };
let ex3 = () => {
  let result = sefeProp('name')(user).map(x => fp.first(x));
  return result._value;
}
console.log('---练习3---', ex3());

//练习4
let ex4 = function(n) {
  if(n) {
    return parseInt(n);
  } 
}
let res4 = function(n) {
  let result = Maybe.of(n).map(n => parseInt(n))
  return result._value ? result._value : undefined;
}
console.log('---练习4---', res4('100'));
console.log('---练习4---', res4(null));
